package com.thread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 使用FutureTask创建线程
 */
@Slf4j(topic = "c.Test3")
public class FutureTaskDemo1 {
    public static void main(String[] args) {
        FutureTask<Integer> task=new FutureTask<>(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                log.debug("running ...");
                Thread.sleep(3000);
                return 100;
            }
        });

        Thread t=new Thread(task,"t3");
        t.start();

        try {
            log.debug("{}",task.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }
}
